<?php

namespace mpend\modules\share\controllers;

use Yii;
use mpend\components\Controller;
use common\helpers\ArrayHelper;
use common\logics\ShareLogic;
use mpend\modules\share\models\SpreadAttractForm;

/**
 * 常见问题与帮助分类接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class DefaultController extends Controller {

    /**
     * 停用token校验
     * @inheritdoc
     */
    public $filterAccessToken = false;

    /**
     * {@inheritdoc}
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
        ];
    }

    /**
     * 问题与帮助分类列表
     * @inheritdoc
     */
    public function actionIndex() {
        $params = Yii::$app->request->get('data');
        if (!$params) {
            return null;
        }
        $data = ShareLogic::parseData($params);
        if ($data) {
            $userId = ArrayHelper::remove($data, 'user_id');
            if ($userId) {
                $data['spread'] = $userId;
            }
        }
        return $data;
    }

    /**
     * 问题与帮助分类列表
     * @inheritdoc
     */
    public function actionIndex3() {
        $params = Yii::$app->request->get('data');
        if (!$params) {
            return null;
        }
        $data = ShareLogic::parseData($params);
        $userId = ArrayHelper::getValue($data, 'user_id');

        if ($userId && $this->token) {
            Yii::error([
                $userId,
                $this->token
            ]);
            $spreadAttract = new SpreadAttractForm();
            $spreadAttract->user_id = $userId;
            $spreadAttract->token = $this->token;
            $spreadAttract->bind();
        }
        return $data;
    }

}
